//
//  TravelTopicPicTableViewCell.m
//  ToWhere
//
//  Created by dllo on 15/11/20.
//  Copyright © 2015年 www.TE.com. All rights reserved.
//

#import "TravelTopicPicTableViewCell.h"
#import <SDWebImageManager.h>
#import <UIButton+WebCache.h>


@interface TravelTopicPicTableViewCell ()

@property (nonatomic, assign) CGFloat wd;
@property (nonatomic, assign) CGFloat kh;


@end

@implementation TravelTopicPicTableViewCell

-(void)dealloc
{
     [_btnPic release];
    [_model release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createView];
    }
    return self;
    
}

-(void)createView
{
    self.btnPic = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [self addSubview:self.btnPic];
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat h = (int)(self.kh / self.wd * (self.frame.size.width ));
    self.btnPic.frame = CGRectMake(5 * kWidth, 5 *kHeight, self.frame.size.width - 10 *kWidth, h);
}

-(void)setModel:(TravelTopicDetailsModel *)model
{
    if (_model != model) {
        [_model release];
        _model  = [model retain];
    }
    
    self.wd =  [model.image_width floatValue];
 
    self.kh = [model.image_height floatValue];
    
    [self.btnPic sd_setBackgroundImageWithURL:[NSURL URLWithString:model.image_url] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"Travel_place"]];
    
    
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
